﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using cwtrock.model;
using cwtrock.syscommon;
using cwtrock.util;

namespace cwtrock.view
{
    public partial class VouQueryFrm : Form
    {
        private static VouQueryFrm frm = null;
        private FrmMain myfrmMain;
      //  private static int QUERY_FLAG = 1;
        public static VoucherListMain vmainfrm;

        public VouQueryFrm()
        {
            InitializeComponent();
            post_no_rtn.Checked = true;
            closed_no_rtn.Checked = true;

           
        }

        #region 单体模式
        /// <summary>
        /// 单体模式
        /// </summary>
        /// <returns></returns>
        public static VouQueryFrm getInstance()
        {
           if (vmainfrm != null)
                return null;

           if (frm == null)
            {
                frm = new VouQueryFrm();
               
             }

            return frm;
        }
        #endregion

        private void query_btn_Click(object sender, EventArgs e)
        {
            // 获取查询条件
            Vouchers v = new Vouchers();

            // 过账的状态
            string ps = "";
            if (post_no_rtn.Checked)
                ps = SysConst.VOUCHER_POST_NO;
            else if (post_yes_rtn.Checked)
                ps = SysConst.VOUCHER_POST_YES;
            else if (post_all_rtn.Checked)
                ps = SysConst.VOUCHER_POST_ALL;

            // 审核的状态
            string cs = "";
            if (closed_no_rtn.Checked)
                cs = SysConst.VOUCHER_CLOSED_NO;
            else if (closed_yes_rtn.Checked)
                cs = SysConst.VOUCHER_CLOSED_YES;
            else if (closed_all_rtn.Checked)
                cs = SysConst.VOUCHER_CLOSED_ALL;

            // 当前用户
            SysUsr currentUser = AppContextProvider.instance.LogUser;

            v.Vpoststat = ps;
            v.Vclosedstat = cs;
            v.Vmakerid = currentUser.Usrid;

            VoucherListMain.voucherQuery = v;
            vmainfrm =  VoucherListMain.getInstance();
            vmainfrm.MdiParent = myfrmMain;
            vmainfrm.Show();
            this.Hide();
        }

        private void VouQueryFrm_FormClosing(object sender, FormClosingEventArgs e)
        {
            myfrmMain = null;
        }

        public FrmMain MyfrmMain
        {
            get { return myfrmMain; }
            set { myfrmMain = value; }
        }
    }
}
